<?php

use yii\helpers\Html;
//use yii\widgets\ActiveForm;
use yii\bootstrap\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\Img;
/* @var $this yii\web\View */
/* @var $model common\models\UserMess */
/* @var $form yii\widgets\ActiveForm */
?>
<script>
    var i=0;
    var j=0;
    $(function(){
        $(".add-exp").click(function(){
            if(i>4) {alert("最多添加5条") ;return false;}
            var input= '<div><div class="col-md-6 col-xs-6 col-md-offset-3 col-xs-offset-3" style="margin-top: 20px">'+
                '<input type="text"  class="form-control" onchange="add(this)" value="" maxlength="400">'+
                '</div>';
            //  alert(html);
            var button= '<div class="col-md-3 col-xs-3 " style="margin-top: 20px"><button type="button" class="btn btn-primary" onclick="reduce(this)">-</button></div></div>';
            $(this).parent().parent().append(input+button);
            i++;
        });



        $(".add-edu").click(function(){
            if(j>4) {alert("最多添加5条") ;return false;}
            var input_1= '<div><div class="col-md-6 col-xs-6 col-md-offset-3 col-xs-offset-3" style="margin-top: 20px">'+
                '<input type="text"  class="form-control" onchange="add_1(this)" value="" maxlength="400">'+
                '</div>';
            //  alert(html);
            var button_1= '<div class="col-md-3 col-xs-3 " style="margin-top: 20px"><button type="button" class="btn btn-primary" onclick="reduce_1(this)">-</button></div></div>';
            $(this).parent().parent().append(input_1+button_1);
            j++;
        });
    });
    function add(th){
        var input_exp='';
        $('#exp-list').find('input').each(function(){
            input_exp+=$(this).val()+'@';
        });
//         var input_a=th.value;
        var exp=$('#usermess-experience');
        exp.attr('value',input_exp);
    }
    function reduce(th){
        i--;
        th.parentNode.parentNode.remove();
        var input_exp='';
        $('#exp-list').find('input').each(function(){
            input_exp+=$(this).val();
        });
//         var input_a=th.value;
        var exp=$('#usermess-experience');
        exp.attr('value',input_exp);
    }
    function add_1(th){
        var input_edu='';
        $('#edu-list').find('input').each(function(){
            input_edu+=$(this).val()+'@';
        });
//         var input_a=th.value;
        var exp=$('#usermess-education');
        exp.attr('value',input_edu);
    }
    function reduce_1(th){
        j--;
        th.parentNode.parentNode.remove();
        var input_edu='';
        $('#edu-list').find('input').each(function(){
            input_edu+=$(this).val();
        });
//         var input_a=th.value;
        var exp=$('#usermess-education');
        exp.attr('value',input_edu);
    }
</script>
<div class="user-mess-form" style="background-color: #fff;border-radius: 10px;<?php if(isMobile()){ echo "padding:20px 100px";} else echo  "padding:20px 10px";?>">
    <?php $form = ActiveForm::begin([
        'fieldConfig' => [
            'template' => "{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
        ],
    ]); ?>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-uid">uid</label>
        <div class="col-md-6 col-xs-6 ">
            <?= $form->field($model, 'uid')->textInput(['maxlength' => true]) ?>
        </div>
    </div>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-role">role</label>
        <div class="col-md-6 col-xs-6 ">
            <?= $form->field($model, 'role')->textInput() ?>
        </div>
    </div>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-position">position</label>
        <div class="col-md-6 col-xs-6  ">
            <?= $form->field($model, 'position')->textInput(['maxlength' => true]) ?>
        </div>
    </div>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-email">email</label>
        <div class="col-md-6 col-xs-6  ">
            <?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
        </div>
    </div>

    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-age">用户名</label>
        <div class="col-md-6 col-xs-6">
            <?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?>
        </div>
        <div class="col-md-3 col-xs-3">
            <p>建议使用真实姓名</p>
        </div>
    </div>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-sex">头像</label>
        <div class="col-md-6 col-xs-6">
            <?php
            $timestamp=time();
            $image=false;
            if(Img::findOne($model->id)) $image=Img::findOne($model->id)->img_small;
            echo $form->field($model, 'pic')->widget(\kartik\file\FileInput::classname(), [
                'name' => 'UserMess[pic]',
                'options'=>[
                    'accept' => 'image/*',
                    'multiple'=>false,
                ],
                'pluginOptions' => [
                    'uploadUrl' => \yii\helpers\Url::to(['usermess/upload']),
                    'uploadExtraData' => [
                        'timestamp' => $timestamp,
                        'maxFileCount' => 1
                    ],
                    'initialPreview'=>[
                        Html::img($image?Yii::$app->request->baseUrl.$image:'demo.png', ['class'=>'file-preview-image', 'alt'=>'头像', 'title'=>'头像']),
                    ],
                    'initialCaption'=>"尺寸230x230",
                    'overwriteInitial'=>true
                ]
            ]);
            ?>
        </div>
    </div>

    <br>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-sex">性别</label>
        <div class="col-md-6 col-xs-6">
            <label class="radio-inline">
                <input type="radio" name="UserMess[sex]" id="inlineRadio1" value="1"> 男
            </label>
            <label class="radio-inline">
                <input type="radio" name="UserMess[sex]" id="inlineRadio2" value="0"> 女
            </label>
        </div>
    </div>
    <br>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-age">出生日期</label>
        <div class="col-md-6 col-xs-6">
            <?php
            echo $form->field($model, 'age')->widget(\kartik\date\DatePicker::className(),[
                'name' => 'check_issue_date',
                'value' => date('d-M-Y', strtotime('+2 days')),
                'options' => ['placeholder' => '选择日期'],
                'pluginOptions' => [
                    'format' => 'yyyy-mm-dd',
                    'todayHighlight' => true
                ]
            ]);?>
        </div>
    </div>


    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-age">微信号</label>
        <div class="col-md-6 col-xs-6">
            <?= $form->field($model, 'wechat')->textInput(['maxlength' => true]) ?>
        </div>
    </div>

    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-addressPro">省份</label>
        <div class="col-md-2 col-xs-2">
            <?php
            $url=\yii\helpers\Url::to(['usermess/listcity']);
            echo $form->field($model, 'addressPro')->dropDownList(ArrayHelper::map(\common\models\AddressProvince::find()->all(),'code','short_name'),
                [
                    'prompt'=>'请选择地区',
                    'onchange'=>'
                   $.post("'.$url.'?&proid='.'"+$(this).val(),function(data){
                       $("select#usermess-addresscity").html(data);
                   });',
                ]
            )?>
        </div>

        <label class="control-label col-md-2 col-xs-2 text-right" for="usermess-addressCity">城市</label>
        <div class="col-md-2 col-xs-2">
            <?php
            $url=\yii\helpers\Url::to(['usermess/listdistrict']);
            echo $form->field($model, 'addressCity')->dropDownList(ArrayHelper::map(\common\models\AddressCity::find()->all(),'code','name'),
                [
                    'prompt'=>'请选择地区',
                    'onchange'=>'
                           $.post("'.$url.'?&cityid='.'"+$(this).val(),function(data){
                               $("select#usermess-addressdistrict").html(data);
                           });',
                ]
            ) ?>
        </div>
    </div>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-addressDistrict">区/县</label>
        <div class="col-md-2 col-xs-2">
            <?php echo $form->field($model, 'addressDistrict')->dropDownList(ArrayHelper::map(\common\models\AddressDistrict::find()->all(),'code','name'),
                [
                    'prompt'=>'请选择',
                ]
            ) ?>
        </div>
    </div>
    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-address">详细地址</label>
        <div class="col-md-6 col-xs-6">
            <?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
        </div>
    </div>


    <div class="row">
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-experience">职业经历</label>
        <div class="col-md-6 col-xs-6">
            例如：百度  市场总监
        </div>
    </div>
    <div class="row hidden">
        <div class="col-md-6 col-xs-6 col-md-offset-3 col-xs-offset-3">
            <input type="text" id="usermess-experience" class="form-control"  name="UserMess[experience]" value="" maxlength="400" placeholder="公司名称 您的职位">
        </div>
    </div>
    <div class="row" id="exp-list">
        <div class="col-md-6 col-xs-6 col-md-offset-3 col-xs-offset-3">
            <input type="text"  class="form-control" onchange="add(this)" value="" maxlength="400" placeholder="公司名称 您的职位">
        </div>
        <div class="col-md-3 col-xs-3">
            <button class="btn btn-primary add-exp" type="button" >添加</button>
        </div>
    </div>
    <br>
    <div class="row hidden">
        <div class="col-md-6 col-xs-6 col-md-offset-3 col-xs-offset-3">
            <input type="text" id="usermess-education" class="form-control" name="UserMess[education]" value="" maxlength="400" placeholder="学校名称 专业方向">
        </div>
    </div>
    <div class="row" >
        <label class="control-label col-md-3 col-xs-3 text-right" for="usermess-education">教育经历</label>
        <div class="col-md-6 col-xs-6">
            例如：清华大学 建筑工程
        </div>
    </div>
    <div class="row"  id="edu-list">
        <div class="col-md-6 col-xs-6 col-md-offset-3 col-xs-offset-3">
            <input type="text"  class="form-control"  onchange="add_1(this)" value="" maxlength="400" placeholder="学校名称 专业方向">
        </div>
        <div class="col-md-3 col-xs-3">
            <button class="btn btn-primary add-edu" type="button">添加</button>
        </div>
    </div>

    <div class="hidden">
        <?= $form->field($model, 'weight')->textInput() ?>
        <?= $form->field($model, 'create_at')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'updated_at')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'res1')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'res2')->textInput(['maxlength' => true]) ?>

        <?= $form->field($model, 'res3')->textInput(['maxlength' => true]) ?>
    </div>
    <br>
    <div class="row  text-center">
        <div class="col-md-2 col-md-offset-5 col-xs-4 col-xs-offset-4">
            <div class="form-group">
                <?= Html::submitButton($model->isNewRecord ? 'Create' : '保存', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary btn-block','name'=>'sub_b']) ?>
            </div>
        </div>
    </div>

    <?php ActiveForm::end(); ?>

</div>
